package com.spring.security.study.security_test.controller;
import com.spring.security.study.security_test.api.SysUser;
import com.spring.security.study.security_test.service.SysUserService;
import com.spring.security.study.security_test.utils.SysUserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统用户表 Controller
 *
 * @author lby
 * @since 2021-01-11
 */
@RestController
@Slf4j
@Api(value = "SysUser", tags = "系统用户表管理")
@AllArgsConstructor
@RequestMapping("sysUser")
public class TestController {

    private final SysUserService sysUserService;


    /**
     * 测试权限01
     */
    @ApiOperation(value = "测试权限01")
    @GetMapping("/test-permission")
    @PreAuthorize("@pms.hasPermission('sys_user_view')")
    public String permissionTest(){
        log.info("没有权限");
        return "success";
    }

    /**
     * 获取当前登录人
     */
    @ApiOperation(value = "获取当前登录人")
    @GetMapping("/get-info")
    @PreAuthorize("@pms.hasPermission('sys_user_view')")
    public String getUser(){
        String user = SysUserUtils.getUser();
        SysUser sysUser = new SysUser();
        sysUser.setId(Integer.valueOf(user));
        SysUser sysUser1 = sysUser.selectById();
        log.info("当前登录人:{}",sysUser1);
        return "success";
    }


}
